package com.dd.ms.log.api.pojo.dto;

import com.dd.ms.common.pojo.annotation.Explanation;
import lombok.*;

import java.io.Serializable;
import java.time.Instant;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/6/28 11:58
 * @Description 日志记录数据传输对象
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Explanation("日志体")
public class LogEntryDTO implements Serializable {
    @Explanation(value = "时间相关字段（核心）, 使用ISO8601格式的时间戳")
    private Instant timestamp;
    @Explanation(value = "时区标识 \"Asia/Shanghai\"")
    private String timezone;
    @Explanation(value = "日志元数据 日志级别枚举 ERROR/WARN/INFO/DEBUG")
    private String level;
    @Explanation(value = "服务名")
    private String serviceName;
    @Explanation(value = "主机IP 如 \"192.168.1.100\"")
    private String hostIp;
    @Explanation(value = "主机名")
    private String hostName;
    @Explanation(value = "分布式追踪 分布式追踪ID")
    private String traceId;
    @Explanation(value = "日志主体 中文分词")
    private String message;
    @Explanation(value = "错误专用字段（ERROR级时才有值）禁用自动映射")
    private ErrorDetail errorDetail;
    @Explanation(value = "性能指标 响应耗时（毫秒）")
    private Long durationMs;

    @Getter
    @Setter
    @Builder
    @Explanation(value = "嵌套错误对象")
    private static class ErrorDetail {
        @Explanation(value = "错误类型：SYSTEM/BUSINESS")
        private String type;
        @Explanation(value = "错误码（兼容字母数字混合）")
        private String code;
        @Explanation(value = "不索引长文本")
        private String stackTrace;
    }
}
